<?php
/**
 * Note: *
 */
namespace App\Services;

use Illuminate\Support\Facades\Http;

class PlatformNotifyService
{
    private array $notifyUrl;

    public function __construct()
    {
        $this->notifyUrl = config('admin.platform_notify_url');
    }

    private function requestGet(string $url)
    {
        try {
            $res = Http::retry(1, 300)->timeout(5)->get($url);
            $res->throw();
            info(__METHOD__, [$res]);
        } catch (\Exception $e) {
            report($e);
            return false;
        }
        return $res;
    }

    private function requestPost(string $url, array $params = [])
    {
        try {
            $res = Http::retry(1, 300)->timeout(5)->post($url, $params);
            $res->throw();
            info(__METHOD__, [$res]);
        } catch (\Exception $e) {
            report($e);
            return false;
        }
    }

    /**
     * 手机号
     * @return void
     */
    public function resetCacheBlackMobile()
    {
        if (!$this->notifyUrl) return ;
        foreach ($this->notifyUrl as $notifyUrl) {
            $this->requestGet("{$notifyUrl}/". __FUNCTION__);
        }
    }

    /**
     * IP
     * @return void
     */
    public function resetCacheBlackIp()
    {
        if (!$this->notifyUrl) return ;
        foreach ($this->notifyUrl as $notifyUrl) {
            $this->requestGet("{$notifyUrl}/". __FUNCTION__);
        }
    }

    /**
     * 身份证
     * @return void
     */
    public function resetCacheBlackIdCard()
    {
        if (!$this->notifyUrl) return ;
        foreach ($this->notifyUrl as $notifyUrl) {
            $this->requestGet("{$notifyUrl}/". __FUNCTION__);
        }
    }

    /**
     * UUID
     * @return void
     */
    public function resetCacheBlackUuid()
    {
        if (!$this->notifyUrl) return ;
        foreach ($this->notifyUrl as $notifyUrl) {
            $this->requestGet("{$notifyUrl}/". __FUNCTION__);
        }
    }
}
